﻿#ifndef XMESSAGEBOX_H
#define XMESSAGEBOX_H

#include "XMessageBox_global.h"
#include <QDialog>
#include <QDialogButtonBox>
#include <QLabel>
#include <QList>
namespace Ui {
    class XMessageBox;
}

class XMESSAGEBOXSHARED_EXPORT XMessageBox : public QDialog {
    Q_OBJECT
public:
    XMessageBox(QWidget *parent = 0);
    ~XMessageBox();

    enum Icon{
        Warning=1,
        Critical=2,
        Information=3,
        About=4
        };

    enum ButtonId{
       Yes=0x000001,
	   Save=0x000010,
	   Ok=0x000100,
       No=0x001000,
	   Cancel=0x010000,
       Discard=0x100000,
       Start=0x000001,
       Last=0x100000
    };

	enum ButtonIdRole{
		AcceptRole=1,
		RejectRole,
		YesRole,
		NoRole
	};

    Q_DECLARE_FLAGS(ButtonIds, ButtonId)

    XMessageBox(QWidget *parent,Icon icon,const QString &title, const QString &text, ButtonIds buttons, ButtonId defaultButton);

    void setText(const QString &text,int wid=350);
    void setIcon(Icon icon);
    void setDefaultButton(ButtonId defaultButton);
	void setDefaultButton(QPushButton * is_button );

    void setStandardButtons(ButtonIds buttons);
	
    QPushButton *button(ButtonId getBtn);
    QPushButton *addButton(ButtonId btn);
	QPushButton *addButton(const QString &text,ButtonIdRole role);
    int exec();

    static int warning(QWidget *parent, const QString &title, const QString &text, ButtonIds buttons=Yes, ButtonId defaultButton=Yes);
    static int critical(QWidget *parent, const QString &title, const QString &text, ButtonIds buttons=Yes, ButtonId defaultButton=Yes);
    static int information(QWidget *parent, const QString &title, const QString &text, ButtonIds buttons=Yes, ButtonId defaultButton=Yes);
	static int question(QWidget *parent, const QString &title, const QString &text, ButtonIds buttons=Yes, ButtonId defaultButton=Yes);
    static void about(QWidget *parent, const QString &title, const QString &text);

    
    QLabel *label;
    QLabel *label1;
    QLabel *iconLabel;

    QDialogButtonBox *box;
    QPushButton *yes_btn;
    QPushButton *save_btn;
    QPushButton *ok_btn;
	QPushButton *no_btn;
	QPushButton *cancel_btn;
	QPushButton *discard_btn;

protected:
    void changeEvent(QEvent *e);

private:
    Ui::XMessageBox *ui;
    void Xexec();
    void init(QWidget *parent);
    QString SetSize(const QString &text,int wid);
    void SetLayout();

	QList<int> list;
	QList<QAbstractButton *> list_btn;

    int ret;
	int is_default;

	QPushButton *is_btn;
    bool  is_has;

private slots:
    void clickBtn(QAbstractButton *);
};

Q_DECLARE_OPERATORS_FOR_FLAGS(XMessageBox::ButtonIds)

#endif // XMESSAGEBOX_H
